#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct student {
	char* name;
	int age;
};

int com_stu1(const void* p1, const void* p2) {
	return strcmp(((struct student*)p1)->name, ((struct student*)p2)->name);
}

int com_stu2(const void* p1, const void* p2) {
	return ((struct student*)p1)->age - ((struct student*)p2)->age;
}

int com_stu3(const void* p1, const void* p2) {
	return *(int*)p1 - *(int*)p2;
}

void swap(char* p1, char* p2, size_t width) {
	for (int i = 0; i < width; i++) {
		char tmp = p1[i];
		p1[i] = p2[i];
		p2[i] = tmp;
	}

}

void Bubbsort(void* ps, size_t sz, size_t width, int (*com_stu)(const void*,const void*)) 
{
	for (int i = 0; i < sz - 1; i++) 
	{
		int flag = 0;
		for (int j = 0; j < sz - 1 - i; j++) 
		{
			if (com_stu((char*)ps + j * width, (char*)ps + (j+1)*width)>0) 
			{
				swap((char*)ps + j * width, (char*)ps + (j + 1) * width, width);
				flag = 1;
			}	
		}
		if (!flag)
		{
			break;
		}
	}
}


int main() {
	//struct student stu[3] = { {"zhangsan",18},{"wangwu",23},{"lisi",31} };
	int stu[10] = { 234,64,23,675,23,8,32,90,456,5 };
	int sz = sizeof(stu) / sizeof(stu[0]);
	int width = sizeof(stu[0]);
	Bubbsort(stu, sz, width, com_stu3);
	for (int i = 0; i < sz ; i++) {
		//printf("%s %d\n", stu[i].name, stu[i].age);
		printf("%d \n", stu[i]);

	}
}